import Taro from "@tarojs/taro";
import { computed, ref } from "vue";

const history = ref<string[]>(["认识糖尿病", "糖尿病一定会有症状吗？"]);
export const useSearchHistory = () => {
  const currentHistory = computed(() => history.value);
  const insertHistory = (text: string) => {
    if (!history.value.includes(text)) {
      history.value.push(text);
    }
  };

  const clearHistory = () => {
    Taro.showModal({
      content: "确认删除全部历史记录？",
      success: () => {
        history.value = [];
      },
      fail: () => {},
    });
  };

  return { insertHistory, clearHistory, currentHistory };
};
